﻿<?PHP
session_start();
date_default_timezone_set("Asia/Chongqing");
include("../config/connect.php");
include("../public/common.php");
include("../public/biaoqing.php");

if( !HasLogin() ) 
{
	$url = "Location:login.php?ref=like.php";
	header($url);
}

$email = $_SESSION["email"];
$userid = $_SESSION["userid"];
$nickname = $_SESSION["nickname"];

$input_tradeid = "";
$showtype = CheckUrlParamNoDie("showtype");
$opt = CheckUrlParamNoDie("opt");
$id = CheckUrlParamNoDie("id");
$nPage = SetUrlParamInt("page");
if ($nPage == "") $nPage = 1;

if ($opt == "del" && $id != "")
{
	mysql_query("delete from tsj_favorite where item_id=$id and user_id=$userid");
	mysql_query("update goods_items set favorite=favorite-1 where id=$id");
//	echo "update goods_items set favorite=favorite-1 where id=$id";
//	exit;
}

//分页获取商品总数
$Count = mysql_fetch_assoc(mysql_query("select count(*) as tmp from tsj_favorite where user_id=$userid"));
$allLikeCount = $Count["tmp"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?PHP echo $nickname; ?>家的宝贝 - 兔丝街</title>
<link type="text/css" rel="stylesheet" href="../css/base.css" />
<link type="text/css" rel="stylesheet" href="../css/person.css" />
<script language="javascript" src="../js/common.js"></script>
</head>
<body class="bShare">
<div id="wrapper">
<!---head kaishi--->
     <?php
		include("../headtop.php"); 
	?>
<!-----head 结束----->
    <div id="main" class="person">
    	<!---左侧开始--->
    	<div class="grid_3">
        	<div class="person_left">
            	<div class="person_info">
                    <!---侧栏导航 kaishi--->
					<?php
                    	include("sidebarnav.php"); 
                    ?>
                    <!------------>
                </div>
            	
            </div>
        </div>     
        <!---右侧--->
      	<div class="grid_9">
        	<div id="editGoods">
        	<div class="edit_left">
            	<div class="Per">
                	<ul>
                    	<li id="perEdit" style="float:right"><a href="edit_items.php">我要分享宝贝</a></li>
                		<li><a href="index.php">我分享的宝贝</a></li>
                        <li class="as"><a href="like.php">我喜欢的宝贝</a></li>
                    </ul>
                </div>
        	<?php 
				if($allLikeCount == 0){
			?>
            	<div id="empty">
                	<h2>您的兔宝阁是空的，赶紧行动吧！您还可以：</h2>
                    <ul>
                    	<li>马上去<a href="edit_items.php" >收藏宝贝</a></li>
                        <li>看看<a href="../tag/" target="_blank" >兔丝们的宝贝</a></li>
                    </ul>
              	</div>
            <?php }else{ ?>
        	<div class="personContent2">
			<?php
            $PAGE_SIZE = 20; //每页数量
            $limit = " limit ". ($nPage-1)*$PAGE_SIZE .",$PAGE_SIZE";

            $sql = "select * from tsj_favorite,goods_items where tsj_favorite.user_id=$userid and goods_items.id=tsj_favorite.item_id";
            $sql .=" order by tsj_favorite.time desc".$limit;
			
            $result = mysql_query( $sql );;
			$i = 0;
			while( $result && $row = mysql_fetch_assoc( $result ))
			{
            ?>
            	<!--------->
            	<div class="twitter_Feed">
                	<div class="tw_img left"><a href="../item/?id=<?PHP echo $row["id"]; ?>" target="_blank"><img src="<?PHP echo $row["pic_url"]."_170x170.jpg"; ?>" /></a></div>
                    <div class="tw_cont left">
                    	<p class="t_title"><a href="../item/?id=<?PHP echo $row["id"]; ?>" target="_blank" title="<?PHP echo $row["item_title"]; ?>"><?PHP echo $row["item_title"]; ?></a></p>
                        <p class="t_sheng">售价<em><?PHP echo $row["fee"]; ?></em>元</p>
                        <p class="t_xihuan"><a style="float:left;" class="notlikeit cursor" onclick="onfavorite(<?PHP echo $row["id"]; ?>)" >喜欢</a><b class="f14 red nums" style="float:left; <?php if ($row["favorite"] == 0) echo "display:none;"; ?> "><span id="favorite_<?PHP echo $row["id"]; ?>" ><?PHP echo $row["favorite"]; ?></span></b></p>
                        <p class="t_Rec">推荐说：<span style="color:#666; font-size:12px;"><?PHP echo ReplaceBiaoQing($row["r_desc"]); ?></span></p>
                    </div>
                    <div class="toolsBar">
                    	<div class="tw_tools left"><?PHP
                        $item_time = strtotime($row["time"], time());
						$spanTime = (time() - $item_time) / 3600;
						if ( date('yG', $item_time) == date('yG', time()))
							echo "今天 ".date('G:i', $item_time);
						else if ( $spanTime < 48)
							echo "昨天 ".date('G:i', $item_time);
						else
							echo date('m月j日 G:i', $item_time);
//						echo mysql_result($result, $i, "time");
						
						?>
                        </div>
                        
                        <div class="tw_action right" style="font-family:'Microsoft YaHei',arial,tahoma,宋体,sans-serif; color:#333;">
                            <div class="tw_wrapper"><a href="?opt=del&id=<?php echo $row["id"] ?>">删除喜欢</a>&nbsp;|</div>
                            <div class="left">
                            <!-- JiaThis Button BEGIN -->
                                <div id="ckepop">
                                    <span class="jiathis_txt left">分享到：</span>
                                    <a class="qzone" href="http://www.jiathis.com/send/?webid=qzone&url=<?PHP echo urlencode("http://www.tusijie.com/item/share_page.php?id=".$row["id"]."&jtss=qzone"); ?>&title=<?PHP echo $row["item_title"]; ?>&pic=<?PHP echo $row["pic_url"]."_250x250.jpg"; ?>&uid=904300&jtss=qzone" target="_blank" title="分享到QQ空间"></a>
                                    <a class="tsina" href="http://www.jiathis.com/send/?webid=tsina&url=<?PHP echo urlencode("http://www.tusijie.com/item/share_page.php?id=".$row["id"]."&jtss=tsina"); ?>&title=<?PHP echo $row["item_title"]; ?>&pic=<?PHP echo $row["pic_url"]."_250x250.jpg"; ?>&uid=904300" target="_blank" title="分享到新浪微博"></a>
                                    <a class="renren" href="http://www.jiathis.com/send/?webid=renren&url=<?PHP echo urlencode("http://www.tusijie.com/item/share_page.php?id=".$row["id"]."&jtss=renren"); ?>&title=<?PHP echo $row["item_title"]; ?>&pic=<?PHP echo $row["pic_url"]."_250x250.jpg"; ?>&uid=904300&jtss=renren" target="_blank" title="分享到人人网"></a>
                                    <a class="tqq" href="http://www.jiathis.com/send/?webid=tqq&url=<?PHP echo urlencode("http://www.tusijie.com/item/share_page.php?id=".$row["id"]."&jtss=tqq"); ?>&title=<?PHP echo $row["item_title"]; ?>&pic=<?PHP echo $row["pic_url"]."_250x250.jpg"; ?>&uid=904300&jtss=tqq" target="_blank" title="分享到腾讯微博"></a>
                                </div>
                                <!-- JiaThis Button END -->
                            </div>
                        </div>
                        
                    </div>                    
                </div>
			 <?php
            }
             ?>   
             
			<?PHP if ($allLikeCount > $PAGE_SIZE) { ?>
              <!----page--start-->
              <div style="" class="grid_12 alpha omega pager">
                	<div id="pageNav">                        
                        <?php	
						$all_page = floor($allLikeCount / $PAGE_SIZE);
						if ($nPage > 1) echo "<a class='pageNext' href='?page=".($nPage-1)."'>上一页</a>";
						
						if($all_page<=13){				
							for($i=1;$i<=$allLikeCount / $PAGE_SIZE;$i++){//数字分页
								$Pageshow = ($i!=$nPage)?"<a href='?page=$i'>".($i)."</a>":"<b>".($i)."</b>";
								echo $Pageshow;
						  	}
						}else{
							for($i=1;$i<=13;$i++){//数字分页
								$Pageshow = ($i!=$nPage)?"<a href='?page=$i'>".($i)."</a>":"<b>".($i)."</b>";
								echo $Pageshow;
						  	}
						}
						
						if($nPage == 13 || $nPage == floor($allLikeCount / $PAGE_SIZE)){
							echo "";
						}else if($nPage < 13){
							echo "<a class='pageNext' href='?page=".($nPage+1)."'>下一页</a>";
						}
						 ?>
            		</div>
            	</div>
                <!----page--end-->
                <?PHP }
				} ?>
                
            </div>
            </div>
            </div>
            <!----右侧结束-------->
        </div>    
    </div>
</div>
<!---网尾 kaishi--->
 <?php
     include("../networkend.php"); 
?>
<!------------>
</body>
</html>
<script language="javascript" src="../js/jquery.min.js"></script>
<script language="javascript">
function onfavorite(id)
{
<?PHP if (!HasLogin()) { ?>

	alert('您还没登录哦~~');
	window.location='user/login.php?ref=';
	return;
<?PHP } else { ?>

	var url = "http://www.tusijie.com/item/item_static.php?opt=favorite&id=" + id + "&userid=<?PHP echo GetUserId(); ?>";
//	alert(url);
	$.ajax({	url: url,
			async: true,
			success:function(res){
//			alert(res);
			if (res == 1)
			{
				nFavorite = document.getElementById("favorite_"+id).innerHTML;
				if (nFavorite == "")
					nFavorite = 0;
				else
					nFavorite = parseInt(nFavorite);
				document.getElementById("favorite_"+id).innerHTML=nFavorite + 1;
			}
			else
				alert("您已经喜欢过了哦~");
           }
		})
<?PHP } ?>
}
</script>

<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F22b7662ec7d02c816ddfd8f6df6e5cea' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20984072-3']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>